<template>
  <!--商品资料-->
  <el-dialog
    :close-on-click-modal="false"
    :title="title"
    :visible.sync="dialogVisible"
    width="500px">
    <div>
      <el-form size="mini" :model="sendForm" label-width="100px"  ref="sendForm" :rules="rules1">
        <el-form-item label="分组名称：" prop="groupName">
          <el-input style="width:150px" v-model="sendForm.groupName" >
          </el-input>
        </el-form-item>
        <el-form-item label="排序：" >
           <el-input style="width:150px" v-model="sendForm.sort" autocomplete="off" ></el-input>
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
          <el-button @click="handleClose">取 消</el-button>
          <el-button type="primary" @click="handleConfirm" :loading="btnLoading">确认</el-button>
      </span>
  </el-dialog>
</template>
<script>
import {goodsSortList} from '@/api/allInLine/goods'
import {getWhGroupUpdate} from '@/api/allInLine/management'
import { mapGetters } from 'vuex'
import { Message } from 'element-ui';

const defaultSendForm={
  groupName:'',
  warehouseGroupId:'',
  sort:0,
};

export default {
  name: "index",
  data(){
    return {
      goodSortList:[],
      dialogVisible:false,
      btnLoading:false,
      sendForm:JSON.parse(JSON.stringify(defaultSendForm)),
      rules1:{
        groupName:[{required: true, message: '请填写分组名称', trigger: 'blur'},],
      },
      options:[],
      title:''

    }
  },
  props: {
    },
  computed: {
    ...mapGetters([
      'name',
      'mobile',
      'userId'
    ]),
  },
  components : {

  },
  created() {
    this.getSortList()
  },
  filters: {

  },
  methods:{
    //显示
    showPop(item){
      if(item){
        this.title = '编辑分组'
        this.sendForm.warehouseGroupId = item.warehouse_group_id
        this.sendForm.groupName = item.group_name
        this.sendForm.sort = item.sort

      }else{
        this.title = '新增分组'
        this.sendForm = JSON.parse(JSON.stringify(defaultSendForm))
      }
      this.dialogVisible = true;
    },

    //关闭
    handleClose(){
      this.dialogVisible = false;
    },

    // 获取商品分类
    getSortList() {
      goodsSortList().then(res=>{
        this.goodSortList=res
      })
    },

    //新增部门
    handleConfirm(){
      const data = JSON.parse(JSON.stringify(this.sendForm))
      getWhGroupUpdate(data).then(res=>{
        Message.success('操作成功')
        this.dialogVisible = false
        this.$emit("update")
      })
        },
  },
}
</script>

<style  lang="scss">

</style>
